﻿using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using evt;
public class ZJHAlert : MonoBehaviour {

	// Use this for initialization
	public static EvtCallBack callback = null;
	public static bool Show = false;
	void Start () {
		ServerEventDispather.getInstance ().AddEventDispather (ServerEvent.ERROR_MSG, OpenView);
		EventTriggerListener.Get (transform.GetChild(2).gameObject).onClick = HideView;
	}

	private void HideView(object data){
		Show = false;
		transform.localPosition = new Vector3(10000,0,0);
		if (callback != null) {
			callback (true);
			callback = null;
		}
	}

	private void OpenView(object data){
		Show = true;
		transform.GetChild (1).GetComponent<Text> ().text = data as string;
		transform.localPosition = Vector3.zero;
	}

	void OnDestroy(){ 
		ServerEventDispather.getInstance ().removeEventListener (ServerEvent.ERROR_MSG);
	}

	
	// Update is called once per frame
	void Update () {
	
	}
}
